using System.Collections.Generic;
using System.Web.UI.WebControls;
using ValidationFramework.Reflection;

namespace ValidationFramework.Web.ASP
{
    public class RegexRuleClientValidationGenerator : IClientValidationGenerator
    {


        /// <inheritdoc />
        public IList<BaseValidator> CreateWebClientValidators(Rule rule, InfoDescriptor infoDescriptor)
        {
            var regexRule = (RegexRule) rule;
		    var webValidator = new RegularExpressionWebValidatorEx
		                           {
                                       ValidationExpression = regexRule.ValidationExpression
		                           };
		    var array = new BaseValidator[1];
		    array[0] = webValidator;
		    return array;
        }


        /// <inheritdoc />
        public bool CanHandleTarget(RuleContext ruleContext)
        {
            return ruleContext.Rule is RegexRule;
        }
    }
}